home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / rm_om.zip / OPTION.C < prev    next >
C/C++ Source or Header  |  1991-10-16  |  1KB  |  40 lines

  1. /*
  2. **    Return options set by string as value (type OPTION);
  3. **    mask defines which bits can be set, number returns possible numeric
  4. **    parameter value.  Examples of masks, option strings and returned
  5. **    option bits:
  6. **    OPTIONA|OPTIONB        a    OPTIONA
  7. **    OPTIONA|OPTIONB        B    OPTIONB
  8. **    OPTIONA|OPTIONB        x    OPTERR
  9. **    OPTIONA|OPTIONB        ax    OPTIONA|OPTERR
  10. **    OPTIONA|OPTNUM        a    OPTIONA
  11. **    OPTIONA|OPTNUM        a31    OPTIONA|OPTNUM    (and *number set to 31)
  12. **    OPTIONA|OPTNUM        14a    OPTNUM|OPTERR    (and *number set to 14)
  13. */
  14.  
  15. #include    <ctype.h>
  16. #include    "option.h"
  17. #include    "formatch.h"
  18.  
  19. OPTION option(string,mask,number)
  20. char string[];
  21. OPTION mask;
  22. unsigned int *number;    {
  23.     unsigned register char c;
  24.     int nonum=1;
  25.     OPTION l;
  26.  
  27.     for(l=0L; c=tolower(*string); string++)
  28.         if(islower(c) && ((mask>>(c-'a'))&1) && !(l&OPTNUM))
  29.             l |= 1L<<(c-'a');
  30.         else if(isdigit(c) && mask&OPTNUM)    {
  31.             if(nonum) *number=nonum=0;
  32.             *number = *number*10+c-'0';
  33.             l |= OPTNUM;
  34.         } else if(c==*optsepar)
  35.             *optsepar='\0';
  36.         else if(!isspace(c))
  37.             l |= OPTERR;
  38.     return l;
  39. }
  40.